package chemistry;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class ElementList {
	private ArrayList<Element> elements;
	private HashMap<String, Element> symbolLookup;
	private static List<Integer> nonMetals = Arrays.asList(2, 6, 7, 8, 9, 10, 15, 16, 17, 18, 33, 34, 35, 36, 52, 53, 54, 85, 86, 118);

	public ElementList() throws FileNotFoundException{
		this.elements = new ArrayList<Element>();
		this.symbolLookup = new HashMap<String, Element>();
		//
		InputStream elementIn = ElementList.class.getResourceAsStream("elements.txt");
		Scanner e = new Scanner(elementIn);
		
		while(e.hasNextLine()) {
			e.nextLine();
			int number = e.nextInt();
			String name = e.next();
			String symbol = e.next();
			double mass = e.nextDouble();
			double boil = e.nextDouble();
			double melt = e.nextDouble();
			double densityVapor = e.nextDouble();
			double fusion = e.nextDouble();
			double electronegativity = e.nextDouble();
			double crustPercent = e.nextDouble();
			double ionizationEnergy = e.nextDouble();
			int charge = e.nextInt();
			int atomicRadius = e.nextInt();
			Element element = new Element(name, number, symbol, mass, boil, melt, densityVapor, fusion,
					electronegativity, crustPercent, ionizationEnergy, charge, atomicRadius);
			this.elements.add(element);
			this.symbolLookup.put(symbol, element);
		}
	}
	
	public int getSize() {
		return elements.size();
	}
	
	public Element getElement(String symbol){
		return this.symbolLookup.get(symbol);
	}
	
	public Element getElement(int num){
		return this.elements.get(num);
	}
	
	public boolean isNonMetal(Element e){
		return nonMetals.contains(e.getNumber()); 
	}
	
	public String[] getElementDescriptions(){ //returns a list of elements in
		String[] ed = new String[this.elements.size()];
		int i = 0;
		for(Element element : this.elements){
			ed[i] = element.simpleDescription();
			i++;
		}
		return ed;
	}
}